package service;

import java.util.ArrayList;


import dao.Field;



import model.Location;
import model.MapObject;
import model.MegaSuperMob;
import model.Mob;
import model.Sniper;
import model.SuperMob;

public class Service {

	private Field field;
	private static Service service;

	public static Service getService(){
		if(service == null)
			service = new Service();
		return service;

	}

	private Service(){
		//singleton
	}


	//----------------------------------- Trivielle methoder 
	//	public void createAllLocations(int depth, int width){
	//		
	//		for(int row = 0; row < depth; row++){
	//			for(int col = 0; col < width; col++){
	//				Location loc = new Location(row,col);
	//				Dao.getDAO().addLocation(loc);
	//			}
	//		}
	//		
	//	}
	//	
	//------------------------- Field

	public Field createField(int depth, int width){
		Field f = new Field(depth, width);
		this.field = f;
		return field;
	}
	public Field getField(){
		return field;
	}



	//------------------------- Towers --------------------------
	public void removeTower(MapObject mapObject){
		Service s = service.getService();
		s.getField().clearLocation(mapObject.getLocation());
	}

	//------------ Sniper ---------
	public MapObject createSniper(Location location){

		Service s = Service.getService();

		Sniper sniper = new Sniper(location);
		s.getField().place(sniper, sniper.getLocation());
		return sniper;
	}



	//-------------------------- Mobs -------------------------

	public void removeMob(MapObject mapObject){
		Service s = service.getService();
		s.getField().clearLocation(mapObject.getLocation());

	}

	//------------ SuperMob
	public MapObject createSuperMob(){
		Service s = Service.getService();
		SuperMob sm = new SuperMob(s.getStartLocation());
		s.getField().place(sm, sm.getLocation());
		return sm;
	}
	//------------ MegaSuperMob
	public MapObject createMegaSuperMob(){
		Service s = Service.getService();
		MegaSuperMob msm = new MegaSuperMob(s.getSecondLocation());
		s.getField().place(msm, msm.getLocation());
		return msm;

	}

	//--------------------------- Movement of Mobs
	public void movementOnField(){
		System.out.println("movementOnField");
		Service s = Service.getService();
		Field field = s.getField();
		int depth = field.getDepth();
		int width = field.getWidth();

		for(int row = depth; row >= 0; row--){
			for(int col = width; col >= 0; col--){
				if(field.getObjectAt(row, col).equals(Mob.class)){
					Mob mob = (Mob) field.getObjectAt(row, col);
					Location loc = mob.movement(field);
					field.place(mob, loc);

				}
				else 
				{

				}


			}
		}
		
		
	}



	public Location getStartLocation(){
		Location loc = new Location(0,0);		
		return loc;
	}
	public Location getSecondLocation(){
		Location loc = new Location(0,1);
		return loc;
	}




}
